﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.MBSM.DBUtility;
public partial class Agency_UniteMange : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UNShow();
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Del"))
        {
            string U_id = e.CommandArgument.ToString();
 
            int rtn = 0;
            try
            { HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                rtn = 0;//删除
                if (rtn == 0)
                {
                     Response.Write("<script language=JavaScript>alert('删除失败！');</script>");   
                }
                if (rtn == 1)
                {
                      Response.Write("<script language=JavaScript>alert('删除成功！');</script>");   
                      HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "account", "U_id="+U_id, "../Agency/UniteMange.aspx");
                }
            }
            catch ( Exception ae)
            {
                HZ.Web.WebUtil.Alert("数据异常请重试！", this);
            }
        }
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        UNShow();
    }
    private void UNShow()
    {
        string strConditions = "";
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Unittable";                                               //要查询的表明
        dbPage.Key = "U_id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "*";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "Uname";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        //dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        //08.18
        dr = null;
        db = null;

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        UNShow();
    }
    protected void GridView1_RowUpting(object sender, GridViewUpdateEventArgs e)
    {
        HZ.MBSM.BLL.Uint un = new HZ.MBSM.BLL.Uint();
        TextBox texunname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtUname");
        string _strid=GridView1.Rows[e.RowIndex].Cells[0].Text.Trim();
        if (un.UpdateUnit(texunname.Text.Trim(),_strid)==0)
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "account", "U_id=" + _strid + "Uname="+texunname.Text, "../Agency/UniteMange.aspx");
            GridView1.EditIndex = -1;
            UNShow();
        }
        else
        {
            Response.Write("<script language=JavaScript>alert('修改失败！');</script>");   
        }
    }
}
